home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <memory.h>
- #include <dos.h>
- #define MAX 255
-
- int field;
- int Highlight, Fg, Bg;
-
- char *pulldir(unsigned char row, unsigned char col, char *spec)
- {
- char *allkeys;
- int selection;
- unsigned int errcode;
- /* don't work yet */
- struct find_t b_file;
- struct find_t *(c_file)[MAX];
- char *fileitems[MAX];
- int files, filenum, c;
- static char sel_space[13];
- static char *sel_name = sel_space;
- /* if (strlen(spec)%2)
- strcat(spec," ");
- /* find first file in current directory */
-
- filenum = 0;
- c_file[filenum] = (struct find_t *)calloc(1, sizeof(struct find_t));
- errcode = _dos_findfirst(spec, _A_NORMAL, &b_file);
- if (errcode != 0)
- return(NULL);
-
- memcpy(c_file[filenum], &b_file, sizeof(struct find_t));
-
- filenum++;
- c_file[filenum] = (struct find_t *)calloc(1, sizeof(struct find_t));
- while(_dos_findnext(&b_file) == 0) {
- c_file[filenum] = (struct find_t *)calloc(1, sizeof(struct find_t));
- memcpy(c_file[filenum], &b_file, sizeof(struct find_t));
- filenum++;
- }
- filenum--;
-
- sortfiles(c_file, filenum+1);
- allkeys = (char *)calloc(filenum,sizeof(char));
-
- /* */
- for (files = 0; files <= filenum; files++) { /* others have files <= */
- fileitems[files] = (char *)calloc(1, 13);
- fileitems[files] = c_file[files]->name;
- allkeys[files] = c_file[files]->name[0];
- }
- /* sort files */
- selection = pulldown(row, col, spec, fileitems, allkeys, filenum+1, 16);
- if (selection == 255)
- return(NULL);
- /* */
- printf("\nselected file %s is %ld bytes long",
- c_file[selection]->name, c_file[selection]->size);
- return(1);
- /* */
- strcpy(sel_name,c_file[selection]->name);
- for (files = 0; files <= filenum; files++) {
- free(fileitems[files]);
- free(c_file[files]);
- }
- return(sel_name);
- }
-
- int pulldown(char row, char col, const char *header, const char *prompt[], const char *keys, int lines, int width)
- {
- /* ========================================================================
- * Displays a pull down menu and returns with selection number
- * ===================================================================== */
- char leftcol, rightcol, ch, spaces;
- extern Fg, Bg;
- int count, keycode, txtpos, lastpos, maxpos,insert = 1;
- unsigned char field; /* declared here to over-ride extern use */
- char *genp = "none";
- char bottom[80];
- unsigned c, scroll=0, lastscroll, showlines;
-
- /* align header and width */
- if (!(strlen(header)%2))
- strcat(header,"═");
- if(width%2) width++;
-
- reverse(0);
- leftcol = col+strlen(prompt[field])+2;
-
- if (row < 3)
- row = 3;
- if (col < 3)
- col = 3;
- if (row > 20)
- row = 20;
- if ((col+width) > 78)
- col = 78 - width;
- if (lines < 22-row)
- showlines = lines;
- else showlines = 22-row;
-
- /* make box for menu bar */
- locate(row, col);
- printf("╒");
- spaces = ((width - strlen(header))/2) - 1;
- if (spaces > 0)
- for (;(spaces); spaces--)
- putch('═');
- printf("%s", header);
- spaces = ((width - strlen(header))/2) - 1;
- if (spaces > 0)
- for (;(spaces); spaces--)
- putch('═');
- printf("╕");
- row++;
-
- for (spaces = 0; spaces < (width-2); spaces++)
- bottom[spaces] = '─';
- bottom[width-3] = '\0';
- locate(row+showlines, col);
- printf("└%s┘▒",bottom);
- for (spaces = 0; spaces < (width-2); spaces++)
- bottom[spaces] = '▒';
- bottom[width-3] = '\0';
- locate(row+showlines+1, col+1);
- printf("%s▒▒",bottom);
-
- /* initial display of fields */
- for (count = 0; count < showlines; count++) {
- locate(row+count, col);
- spaces = (width - strlen(prompt[count]) - 3);
- printf("│%s",prompt[count]);
- for (;(spaces); spaces--)
- putch(' ');
- putch('│');
- putch('▒');
- }
- col++;
-
-
- for (field=0; field < showlines;) {
- reverse(1);
- locate(row+field,col);
- printf("%s", prompt[field+scroll]);
- locate(row+field,col);
- fflush(stdin);
- while(!kbhit())
- ;
- if ((keycode = getch()) != 00)
- switch (keycode) {
- case 13:
- reverse(0);
- locate (23,1);
- return(field+scroll);
- case 27:
- /* no change to original string */
- reverse(0);
- locate (23,1);
- return(255);
- default:
- keycode = toupper(keycode);
- if(( c = choices(keycode,keys) ) != 255) {
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
- if(keys[c] == keys[scroll+field]) /* if same letter, call again */
- if((c = choices(keycode,&keys[scroll+field+1])) == 255)
- /* if no more for same letter, restore value of c */
- c = scroll+field;
- else
- /* add c to last offset */
- c = c + scroll + field + 1;
- if(c > scroll+field) {
- /* if lower on list */
- field = c - scroll;
- if (field > (showlines - 1)) {
- /* if not in current scroll window */
- scroll = c;
- field = 0;
- }
- if (scroll > (lines - showlines)) {
- /* if in last scroll window */
- scroll = lines - showlines;
- field = (c - (lines - showlines));
- }
- }
- else {
- /* if lower on list */
- field = c - scroll;
- if (c < scroll) {
- /* if not in current scroll window */
- scroll = c;
- field = 0;
- }
- if (scroll > (lines - showlines)) {
- /* if current window is last scroll window */
- scroll = lines - showlines;
- field = (c - (lines - showlines));
- }
- }
-
- for (count = 0; count < showlines; count++) {
- locate(row+count, col-1);
- spaces = (width - strlen(prompt[count+scroll]) - 3);
- printf("│%s",prompt[count+scroll]);
- for (;(spaces); spaces--)
- putch(' ');
- }
-
- reverse(1);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
- locate(row+field,col);
- /* return(c); */
- }
- break;
- } /* end of normal key switch */
- else { /* get extended key */
- keycode = getch();
- lastscroll = scroll;
- switch(keycode) {
- case 71:
- /* -----Home */
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
- field = 0;
- if (scroll) {
- scroll = 0;
- }
- break;
- case 73:
- /* -----Page Up */
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
- if (field == 0)
- if (scroll >= showlines)
- scroll -= showlines;
- else scroll = 0;
- else
- field = 0;
- break;
- case 72:
- /* -----Up */
- case 75:
- /* -----Left arrow */
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
-
- if (field)
- field--;
- else
- if (scroll)
- scroll--;
- else {
- field = showlines - 1;
- scroll = lines - showlines;
- }
- break;
- case 79:
- /* -----End */
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
-
- field = showlines - 1;
- scroll = lines - showlines;
- break;
- case 81:
- /* -----Page Down */
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
- if(field == showlines-1) {
- if (lines > (scroll + showlines))
- scroll += showlines;
- if (scroll > (lines - showlines))
- scroll = lines - showlines;
- }
- else
- field = showlines-1;
- break;
- case 80:
- /* -----Down */
- case 77:
- /* -----Right arrow */
- reverse(0);
- locate(row+field,col);
- printf("%s",prompt[field+scroll]);
- if (field < showlines-1)
- field++;
- else
- if (lines > showlines)
- scroll++;
- else {
- field = 0;
- scroll = 0;
- }
- if (scroll > (lines - showlines))
- /*scroll = lines - showlines;*/
- { scroll = 0;
- field = 0; }
- break;
-
- default:
- ;
- /* ignore others */
- }
- if (scroll != lastscroll)
- for (count = 0; count < showlines; count++) {
- locate(row+count, col-1);
- spaces = (width - strlen(prompt[count+scroll]) - 3);
- printf("│%s",prompt[count+scroll]);
- for (;(spaces); spaces--)
- putch(' ');
- }
- }
- }
- }
-
- int sortfiles(struct find_t *items[], int count)
- {
- int i, j, value, dist;
- int strcmp();
- struct find_t *holder;
- struct find_t holding;
- holder = &holding;
- /* bubble sort */
- /*
- for (g = 0; g < count; g++) {
- for (h = g+1; h < count; h++) {
- value = stricmp(items[g]->name, items[h]->name);
- if (value > 0) {
- holder = items[g];
- items[g] = items[h];
- items[h] = holder;
- }
- }
- }
- */
- /* shell sort */
- dist = count/2;
- while (dist > 0) {
- for (i=0;i<(count-dist);i++) {
- j = i; /* in loop ?? */
- ;
- while (j >= 0 && (value = stricmp(items[j]->name, items[j+dist]->name) > 0)) {
- holder = items[j];
- items[j] = items[j+dist];
- items[j+dist] = holder;
- j = j-dist;
- }
- }
- dist = dist/2;
- }
- /* qsort */
- /* qsort(items, sizeof(struct find_t), */
-
- }
-
-